import { setItem } from '@/utils/token'

export default {
  actions: {
    // 接受用户信息
    sendData ({ commit }, token) {
      commit('SENDMAIL', token)
    },
    // 账单
    userBill ({ commit }, data) {
      commit('USEABLE', data.Statistics)
      commit('BILLETS', data.bills)
    }
  },
  mutations: {
    SENDMAIL (state, token) {
      state.token = token
    },
    // 存储账单数据
    USEABLE (state, userBills) {
      userBills.isShow = false
      userBills.surplus = userBills.income - userBills.expenditure
      setItem('REBILLS', userBills)
      state.userBills = userBills
    },
    // 计算天数
    BILLETS (state, billList) {
      const card = {}
      card.a = billList.length
      let b = 0
      billList.forEach(item => {
        b += item.list.length
      })
      card.b = b
      setItem('card', card)
    }
  },
  state: {
    token: '',
    userBills: {}
  },
  getters: {}
}
